<?php 
class M_groups extends CI_Model{
	
	function getlist($filter,$offset,$limit){
		$this->db->limit($limit);
		$this->db->offset($offset);
		$this->db->where('group_active','Y');
		if(!empty($filter)){
			$this->db->where("lower(group_name) LIKE '%".addslashes(strtolower($filter))."%'");
			$this->db->or_where("lower(group_desc) LIKE '%".addslashes(strtolower($filter))."%'");
		}
		$query = $this->db->get('s_usergroups');
		$total = $query->num_rows();
		$arr   = array();
		foreach($query->result() as $q){
			$arr[] = $q; 
		}
		$final = array('results' => $arr,
					   'total'  => $total);
		return json_encode($final);
	}	
	
	function insert($data){
		$this->db->insert('s_usergroups',$data);
	}
	function update($group_id,$data){
		$this->db->where('group_id',$group_id);
		$this->db->update('s_usergroups',$data);
	}
}